//
//  HomeViewController.m
//  StockNetManager
//
//  Created by 小焘无量 on 2023/3/22.
//

#import "HomeViewController.h"
#import "MemberDetailViewController.h"

@interface HomeViewController ()

@property (weak, nonatomic) IBOutlet UITextField *phoneTF;

@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self.phoneTF.keyboardToolbar.doneBarButton setTarget:self action:@selector(queryBtnAction:)];
}

- (IBAction)queryBtnAction:(UIButton *)sender {
    
    if (![self.phoneTF.text isNotBlank]) {
        [MBProgressHUD showMessage:@"请输入手机号"];
        return;
    }
    if (![self.phoneTF.text valiMobile]) {
        [MBProgressHUD showMessage:@"请输入正确的手机号"];
        return;
    }
    
    [self getUserInfoNetwork];
}

-(void)searcPhoneAction {

}

-(void)getUserInfoNetwork {
    
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setObject:self.phoneTF.text forKey:@"phone"];
    
    WeakSelf;
    [MBProgressHUD showLoadingMessage:nil];
    
    [[APIManager manager] Post:URL_queryUserWithPhone parameters:dic success:^(id  _Nonnull responseObject) {
        [MBProgressHUD hideHUD];
        if (NET_RESULT_CODE == 200) {
            UserInfoModel *model = [UserInfoModel mj_objectWithKeyValues:responseObject[@"data"]];
            MemberDetailViewController *vc = [[MemberDetailViewController alloc]initWithModel:model];
            [weakSelf.navigationController pushViewController:vc animated:YES];
            [weakSelf.view endEditing:YES];
        } else {
            NET_SHOW_MSG;
        }
    } failure:^(NSError * _Nonnull error) {
        [MBProgressHUD hideHUD];
        NET_SHOW_ERROR;
    }];
}

@end
